package com.prtek.reminder.presenter;

import android.content.Context;
import com.prtek.iis.grammar.Expression;
import com.prtek.reminder.bean.Notes;
import com.prtek.reminder.model.IMainModel;
import com.prtek.reminder.model.SpeechEventModel;
import com.prtek.reminder.view.MainView;
import java.util.List;

/**
 * Created by jarly on 2018/9/29.
 */

public class MainPresenterImpl implements IMainPresenter, IMainModel.OnCompleteListener,
    SpeechEventModel.SpeechResultMainListener {

  private MainView mMainView;
  private IMainModel mMainModel;
  private SpeechEventModel mSpeechEventModel;

  public MainPresenterImpl(IMainModel mainModel, SpeechEventModel speechEventModel) {
    mMainModel = mainModel;
    mSpeechEventModel = speechEventModel;
  }

  @Override public void setupSpeechEventListener(Context context, Expression expression) {
    mSpeechEventModel.setupSpeechEventListener(context,expression);
    mSpeechEventModel.setSpeechResultMainListener(this);
  }

  @Override public void attachView(MainView mainView) {
    mMainView = mainView;
    mMainModel.onLoadData(this);
  }

  @Override public void deleteNotes(Notes notes) {
    mMainModel.deleteNotes(notes);
  }

  @Override public void refresh() {
    mMainModel.refreshData();
  }

  @Override public void onDestroy() {
    mMainView = null;
  }

  @Override public void removeSpeechListener() {
    mSpeechEventModel.removeSpeechEventListener();
  }

  @Override public void onComplete(List<Notes> createdNotes, List<Notes> expiredNotes) {
    mMainView.setItemDate(createdNotes, expiredNotes);
  }

  @Override public void remindCreate() {
    mMainView.remindCreate();
  }
}
